﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using DAL;

namespace TieuLuanWindowsNC
{
    public partial class frmThemKH : Form
    {
        QLKSEntities db = new QLKSEntities();
        KhachHangBLL khBLL = new KhachHangBLL();
        public static string maPhong;

        //delegate
        public delegate string qlLayMaPhong();
        private qlLayMaPhong lstMaPhong;

        public frmThemKH()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string _reTelePhone = @"^([0][9]\d{8}|[0][1]\d{9})$";
            Regex reTelePhone = new Regex(_reTelePhone);
            if (!reTelePhone.IsMatch(txtPhone.Text))
            {
                MessageBox.Show("Bạn Phải Nhập Số Điện Thoại!");
            }

            string _reCMND = @"^(\d{9})$";
            Regex reCMND = new Regex(_reCMND);
            if (!reCMND.IsMatch(txtCMND.Text))
            {
                MessageBox.Show("Bạn Phải Nhập Số CMND!");
            }

            //string maPhong = lstMaPhong();

            khBLL.themKH(txtName.Text, txtAddress.Text, bool.Parse(cboSex.SelectedValue.ToString()), txtPhone.Text, txtCMND.Text, maPhong.Trim(), cboMaLK.SelectedValue.ToString());

        }

        private class GT
        {
            public bool maGT { get; set; }
            public string tenGT { get; set; }
        }

        private void frmThemKH_Load(object sender, EventArgs e)
        {
            GT gioitinhNam = new GT();
            gioitinhNam.maGT = true;
            gioitinhNam.tenGT = "Nam";

            GT gioitinhNu = new GT();
            gioitinhNu.maGT = false;
            gioitinhNu.tenGT = "Nữ";

            List<GT> lstGT = new List<GT>();
            lstGT.Add(gioitinhNam);
            lstGT.Add(gioitinhNu);

            cboSex.DataSource = lstGT;
            cboSex.DisplayMember = "tenGT";
            cboSex.ValueMember = "maGT";

            cboMaLK.DataSource = db.LoaiKhaches.ToList();
            cboMaLK.DisplayMember = "TenLK";
            cboMaLK.ValueMember = "MaLK";
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtName.Clear();
            txtAddress.Clear();
            txtPhone.Clear();
            txtCMND.Clear();
        }

        //delegate
        public void DKlayMa(qlLayMaPhong lay)
        {
            lstMaPhong = lay;
        }
    }
}
